// UIDemo.cpp : Defines the entry point for the application.
//

#include "stdafx.h"
#include "UIDemo.h"
#include "WidgetWin.h"
#include "MessageLoop.h"

void onExit()
{
}

int APIENTRY _tWinMain(_In_ HINSTANCE hInstance,
                     _In_opt_ HINSTANCE hPrevInstance,
                     _In_ LPTSTR    lpCmdLine,
                     _In_ int       nCmdShow)
{
	UNREFERENCED_PARAMETER(hPrevInstance);
	UNREFERENCED_PARAMETER(lpCmdLine);

/*
	timeBeginPeriod(1);
	Sleep(100);

	for (int i = 0; i < 20; i++)
	{
		DWORD dwStart = timeGetTime();
		Sleep(2);

		ATLTRACE("tickcount: %d\r\n", timeGetTime() - dwStart);
	}
	timeEndPeriod(1);

	for (int i = 0; i < 20; i++)
	{
		DWORD dwStart = timeGetTime();
		Sleep(2);

		ATLTRACE("tickcount: %d\r\n", timeGetTime() - dwStart);
	}
*/


 	// TODO: Place code here.
	MSG msg;
	HACCEL hAccelTable;

	// Initialize global strings
	// LoadString(hInstance, IDS_APP_TITLE, szTitle, MAX_LOADSTRING);
	// LoadString(hInstance, IDC_UIDEMO, szWindowClass, MAX_LOADSTRING);
	// MyRegisterClass(hInstance);

	// Perform application initialization:
	// if (!InitInstance (hInstance, nCmdShow))
	// {
	// 	return FALSE;
	// }
	WidgetWin& window = WidgetWin::getInstance();
	if (!window.createWindow(hInstance, nCmdShow))
	{
		return FALSE;
	}

	hAccelTable = LoadAccelerators(hInstance, MAKEINTRESOURCE(IDC_UIDEMO));

	// Main message loop:
/*
	DWORD dwStart = timeGetTime();

	while (GetMessage(&msg, NULL, 0, 0))
	{
		
		ATLTRACE("tickcount: %d\r\n", timeGetTime() - dwStart);
		dwStart = timeGetTime();

		if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg))
		{
			TranslateMessage(&msg);
			DispatchMessage(&msg);
		}
	}*/

	atexit(onExit);
	MessageLoop& messageLooper = MessageLoop::getInstance();
	messageLooper.init();
	return (int)messageLooper.run();
}